package com.tjbank.cssys.web.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CkOrderRecoveryData;
import com.tjbank.cssys.repository.CkOrderRecoveryDataMapper;
import com.tjbank.cssys.web.service.CkOrderRecoveryDataService;
import com.tjbank.cssys.web.util.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CkOrderRecoveryDataServiceImpl implements CkOrderRecoveryDataService {
    protected static final Logger logger = LoggerFactory.getLogger(CkOrderRecoveryDataServiceImpl.class);
    @Autowired
    private CkOrderRecoveryDataMapper ckOrderRecoveryDataMapper;
    @Autowired
    private RedisService redisService;
    @Value("${loginUserName}")
    private String loginUserNameAdmin;

    @Override
    public PageInfo selectCkOrderRecoverlist(Map<String, String> map, HttpServletRequest request) {
        logger.info("获取催记列表start---参数：param:" + map.toString());
       /* String uuid=UUID.randomUUID().toString();
        redisService.saveThreadIdUserCode(request,loginUserNameAdmin,"selectCkOrderRecoverlist",uuid);*/
        int page = Integer.parseInt(map.getOrDefault("page", "1").toString());
        int pageSize = Integer.parseInt(map.getOrDefault("pageSize", "10").toString());
        PageHelper.startPage(page, pageSize);
        List<CkOrderRecoveryData> list = ckOrderRecoveryDataMapper.selectRecoveryDataList(map);
        PageInfo pageInfo = new PageInfo<>(list);
       /* redisService.del(Thread.currentThread().getId()+uuid);
        redisService.del(Thread.currentThread().getId()+"");*/
        logger.info("获取催记列表end---result：pageInfo:" + pageInfo.toString());
        return pageInfo;
    }

    @Override
    public Map getCkOrderrecoverById(Map<String,String>map) {
        logger.info("获取催记详情start---参数：" + JSONObject.toJSONString(map));
        Map resultMap=new HashMap();
        List<CkOrderRecoveryData> resultList =ckOrderRecoveryDataMapper.getInfomationByPeopldIdAndContractNum(map);
        resultMap.put("info",JSON.toJSONString(resultList.get(0)));
        resultMap.put("dataList",resultList);
        logger.info("获取催记详情end---参数：result:" + JSON.toJSONString(resultMap));
        return  resultMap;
    }

    @Override
    public void insertForeach(List<CkOrderRecoveryData> ckOrderRecoveryDataList) {
        ckOrderRecoveryDataMapper.insertForeach(ckOrderRecoveryDataList);
    }

    @Override
    public List<CkOrderRecoveryData> selectBySerialNumber(List<String> serialNumbers) {
      return   ckOrderRecoveryDataMapper.selectBySerialNumber(serialNumbers);
    }

    @Override
    public void deleteForEach(List<CkOrderRecoveryData> ckOrderRecoveryDatas) {
        ckOrderRecoveryDataMapper.deleteForEach(ckOrderRecoveryDatas);
    }
}
